package com.sisyphus.spinach.network.presenters;

import android.util.Log;

import com.sisyphus.spinach.core.INetTask;

import androidx.annotation.NonNull;
import androidx.lifecycle.LifecycleOwner;
import io.reactivex.rxjava3.disposables.CompositeDisposable;
import io.reactivex.rxjava3.disposables.Disposable;

public class NetLifecycleTask<T, V extends INetTask.View<T>> implements INetTask.Presenter<T, V> {

    private final static String TAG = "SPINACH_PRESENTERS";

    protected V mView;

    private final CompositeDisposable mCompositeDisposable;


    public NetLifecycleTask() {
        mCompositeDisposable = new CompositeDisposable();
    }

    @Override
    public void bind(V view) {
        mView = view;
    }

    @Override
    public void add(@NonNull Disposable d) {
        Log.i(TAG, "LifecycleNetTask >> add()");
        mCompositeDisposable.add(d);
    }


    @Override
    public void onDestroy(@NonNull LifecycleOwner owner) {
        Log.i(TAG, "LifecycleNetTask >> onDestroy()");
        mCompositeDisposable.clear();
    }

}
